﻿using System;
using System.Security.Authentication;
using Informant.ErrorHandling;
using Microsoft.Practices.EnterpriseLibrary.Logging;

namespace Informant.Google.ErrorHandling
{
	public class ErrorHandler : BaseErrorHandler
	{
		/// <summary>
		/// Handles the error by taking application specific and external exceptions and throwing a client friendly exception.
		/// </summary>
		/// <param name="exception">The exception.</param>
		/// <exception cref="System.Security.Authentication.AuthenticationException"/>
		/// <exception cref="System.Net.WebException"/>
		/// <exception cref="System.InvalidOperationException"/>
		public override void MakeExceptionClientFriendly(Exception exception)
		{
			if (exception is ArgumentNullException)
			{
				Logger.Write("AuthenticationException: " + ErrorResources.AuthenticationExceptionInvalidCredentialsOrTargetServerAddress + Environment.NewLine + exception.StackTrace);
				throw new AuthenticationException(ErrorResources.AuthenticationExceptionInvalidCredentialsOrTargetServerAddress);
			}
			else
			{
				base.MakeExceptionClientFriendly(exception);
			}
		}
	}
}
